package com.naraba.socket.biosocket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.rmi.server.ExportException;

/**
 * @auther xjl
 * @date 2020/10/27
 * @description
 **/
public class UserInputHandler implements Runnable {

    private ChatClient chatClient;

    public UserInputHandler(ChatClient chatClient) {
        this.chatClient = chatClient;
    }

    @Override
    public void run() {

        try {
            //接收用户输入的消息
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(System.in)
            );
            //不停的获取reader中的System.in，实现了等待用户输入的效果
            while (true) {
                String input = reader.readLine();
                // 向服务端发送消息
                chatClient.sendToServer(input);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
